function HandleSearchInverstment(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : null;
  this._search = (options && options.search) ? options.search : null;

  if (!this._search) {
    this._search = { keyword: '',
                     dateFrom: null,
                     dateTo: null
                   };
  }
  this._createElements();
};

HandleSearchInverstment.prototype._createElements = function() {
  var _self = this;

  if (this._gui.m1_div) {
    this._gui.m1_advanced.onclick = function() { _self._gui.m1_div.style.display = 'none';
                                                 _self._gui.m2_div.style.display = 'inline';
                                                 _self._search.dateFrom = null;
                                                 _self._search.dateTo = null;
                                                 _self._createElements.call(_self);
                                               };
    
    this._gui.m1_keyword.value = this._search.keyword;
    this._gui.m1_keyword.onchange = function() { _self._search.keyword = this.value; };
    this._gui.m1_keyword.onkeypress = function(e) { _self._search.keyword = this.value;
                                                    var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc(_self._search);
                                                    }
                                                  };
     this._gui.m1_search.onclick = function() { _self._callbackFunc(_self._search); };
  }
  
  if (this._gui.m2_div) {
    this._gui.m2_simple.onclick = function() { _self._gui.m2_div.style.display = 'none';
                                               _self._gui.m1_div.style.display = 'inline';
                                               _self._search.dateFrom = null;
                                               _self._search.dateTo = null;
                                               _self._createElements.call(_self);
                                             };
    this._gui.m2_keyword.value = this._search.keyword;
    this._gui.m2_keyword.onchange = function() { _self._search.keyword = this.value; };
    this._gui.m2_keyword.onkeypress = function(e) { _self._search.keyword = this.value;
                                                    var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc(_self._search);
                                                    }
                                                  };
    this._gui.m2_dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
    this._gui.m2_dateFrom.onclick = function() { var context = this;
                                                 _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                                 return false;
                                               };
    this._gui.m2_dateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                     if (code == 13) {
                                                       _self._callbackFunc(_self._search);
                                                     }
                                                   };
    this._gui.m2_dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
    this._gui.m2_dateTo.onclick = function() { var context = this;
                                               _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                               return false;
                                             };
    this._gui.m2_dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                   if (code == 13) {
                                                     _self._callbackFunc(_self._search);
                                                   }
                                                 };
    this._gui.m2_search.onclick = function() { _self._callbackFunc(_self._search); };
  }
};

HandleSearchInverstment.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleSearchInverstment.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleSearchInverstment.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};

HandleSearchInverstment.toSql = function(search, lag) {
  var from = parseInt(SimpleDate.toStamp(search.dateFrom) - lag);
  var to = parseInt(SimpleDate.toStamp(search.dateTo) - lag);
  return ((search.keyword != '') ? '(' + '(d.amount LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.method LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.note LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.userAccount LIKE \'%' + search.keyword + '%\')' + ')' : '1 = 1') + ' AND ' + ((search.dateFrom) ? '(d.payDate >= \'' + from + '\')' : '1 = 1') + ' AND ' + ((search.dateTo) ? '(d.payDate <= \'' + to + '\')' : '1 = 1');
};